package thread;

public class ThreadDemo9 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
           while (!Thread.currentThread().isInterrupted()){
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
                   try {
                       Thread.sleep(500);//稍后进行中止
                   } catch (InterruptedException ex) {
                       throw new RuntimeException(ex);
                   }
                   break;
               }
           }
        });
        t.start();
        
        Thread.sleep(3000);
        t.interrupt();
    }
}
